<?php
require_once '../inc/configuration.php';
require_once '../inc/connexion_bd.php';

if(!isset($_POST["cbRaisonSoc"])) {$cbRaisonSoc="";} else {$cbRaisonSoc = $_POST["cbRaisonSoc"];}
if(!isset($_POST["txtNom"])) {$txtNom="";} else {$txtNom = $_POST["txtNom"];}
if(!isset($_POST["txtPrenom"])) {$txtPrenom="";} else {$txtPrenom = $_POST["txtPrenom"];}
if(!isset($_POST["txtTel"])) {$txtTel="";} else {$txtTel = $_POST["txtTel"];}
if(!isset($_POST["txtEmail"])) {$txtEmail="";} else {$txtEmail = $_POST["txtEmail"];}
if(!isset($_POST["txtareaObs"])) {$txtareaObs="";} else {$txtareaObs = $_POST["txtareaObs"];}
if(!isset($_POST["action"])) {$action="";} else {$action = $_POST["action"];}

$sql_count = "select count(*) from contacts";
$req_count = mysqli_query($connexion_serveur, $sql_count); 
$count_contacts = mysqli_fetch_array($req_count);



if ($action==1) {
    $sql = "INSERT INTO contacts (id_entreprise, nom, prenom, telephone, email, photo, observations) "
            ."VALUES ( ".$cbRaisonSoc.", '".$txtNom."', '".$txtPrenom."', '".$txtTel."', '".$txtEmail."', ' ' , '".$txtareaObs."')";
$req = mysqli_query($connexion_serveur, $sql); 

echo $sql;
}


?>




<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        // put your code here
        ?>
        <form id="id_form" name="form_contacts" method="post" enctype="multipart/form-data">
            <h4>Ajouter un contact</h4>
              <table>
                <tr>
                    <th>
                        Nom:
                    </th>
                    <td>
                         <input type="text" id="txtNom" name="txtNom">
                    </td>
                </tr>
              <tr>
                    <th>
                        Prénom:
                    </th>
                    <td>
                         <input type="text" id="txtPrenom" name="txtPrenom">
                    </td>
                </tr>
              <tr>
                    <th>
                        Entreprise:
                    </th>
                    <td>
                         <?php 
                        //REQUETE SQL
                        $sql_ent = "SELECT id, raison_sociale FROM entreprises";
                        $req_ent = mysqli_query($connexion_serveur, $sql_ent);
                        
                        $nbre_total = mysqli_num_rows($req_ent);
                        ?>
                          <select name="cbRaisonSoc">
                           <?php  while($data_ent = mysqli_fetch_assoc($req_ent)) {?>  
                            <option value="<?php echo $data_ent["id"]; ?>"><?php echo $data_ent["raison_sociale"]; ?></option>                         
                                    <?php 
                                   } ?>
                          </select>
                    </td>
                </tr>
             <tr>
                    <th>
                        Téléphone:
                    </th>
                    <td>
                         <input type="text" id="txtTel" name="txtTel">
                    </td>
                </tr>
              <tr>
                    <th>
                        Email:
                    </th>
                    <td>
                         <input type="text" id="txtEmail" name="txtEmail">
                    </td>
                </tr>
             <tr>
                    <th>
                        Photo:
                    </th>
                    <td>
                         <input type="file" name="fichier" id="fichier">
                    </td>
                </tr>
             <tr>
                    <th>
                        Observations:
                    </th>
                    <td>
                          <textarea name="txtareaObs" cols="50" rows="10"></textarea>
                    </td>
                </tr>
                  <tr>
                    <td></td>
                    <td>
                        <div><button type="submit" id="envoyer">Envoyer</button></div>
                        <input type="hidden" name="action" id="action" value="1">
                    </td>
                </tr>
                 

        </form>

    </body>
</html>
